
const Goods = require('../model/goods.model')
class GoodsService {
  async crateGoods(obj) {
  const res = await Goods.create(obj)
  console.log('---',res.toJSON(),'toJson');
  return  res
  }
  async updateGoods(id,obj) {
    console.log(id,obj);
  const res = await Goods.update(obj,{where:{id}})
  
  return  res[0]
  }
 async removeGoods(id){
  const res =   await Goods.destroy({where:{id}})
  console.log(res,'res');
  return res
 }
 async destoreGoods(id){
    const res = await Goods.destroy({where:{id}})
    console.log(res,'res');
 }
 async restoreGoods(id){ 
  const res = await Goods.restore({where:{id}})
 console.log(res,'res');}
async findGoodsAll(pagesize,pagenum){
    // const count =await Goods.count()
    // let pageNum = (pagenum -1) * pagesize
    // const rows = await Goods.findAll({offset:pageNum,limit:+pagesize})
    // console.log(count,'cout',rows,'rows');

    //------------------------------------------------
    let pageNum = (pagenum -1) * pagesize
    const {rows,count}=await Goods.findAndCountAll({offset:pageNum,limit:+pagesize})
   
    return {
        count,
        list:rows
    }
  }
}
module.exports = new GoodsService();
